/*
 * LoginBean.java
 * 
 * Copyright (c) 2011 Administrator. 
 * 
 * This file is part of RMS.
 * 
 * RMS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * RMS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with RMS.  If not, see <http ://www.gnu.org/licenses/>.
 */
package com.itrustsolution.rms.managedbean;

import com.icesoft.faces.component.ext.HtmlCommandButton;
import com.icesoft.faces.component.ext.HtmlInputText;
import com.itrustsolution.rms.util.JSFUtil;
import com.itrustsolution.rms.util.RmsUtil;
import java.util.Date;

/**
 *
 * @author Administrator
 */
public class LoginBean {

    private HtmlInputText txtUsername;
    private HtmlInputText txtPassword;
    private HtmlCommandButton btnLogin;

    /** Creates a new instance of LoginBean */
    public LoginBean() {
    }

    public String login_action() {
        System.out.println("-------------------------login_action");
        String username = (String) getTxtUsername().getValue();
        String password = (String) getTxtPassword().getValue();
        System.out.println("username = " + username);
        System.out.println("password = " + password);
        if (!RmsUtil.isNullOrEmpty(username) && !RmsUtil.isNullOrEmpty(password)) {
            //@TODO
            if (username.equals(password)) {
                UserInfoBean userInfo = (UserInfoBean) JSFUtil.getManagedBeanValue("userInfo");
                userInfo.setLoginName(username);
                userInfo.setStartLogin(new Date());
                userInfo.setSuperAdmin(true);
                return "mainpage";
            }
        }
        return "login";
    }

    /**
     * @return the txtUsername
     */
    public HtmlInputText getTxtUsername() {
        return txtUsername;
    }

    /**
     * @param txtUsername the txtUsername to set
     */
    public void setTxtUsername(HtmlInputText txtUsername) {
        this.txtUsername = txtUsername;
    }

    /**
     * @return the txtPassword
     */
    public HtmlInputText getTxtPassword() {
        return txtPassword;
    }

    /**
     * @param txtPassword the txtPassword to set
     */
    public void setTxtPassword(HtmlInputText txtPassword) {
        this.txtPassword = txtPassword;
    }

    /**
     * @return the btnLogin
     */
    public HtmlCommandButton getBtnLogin() {
        return btnLogin;
    }

    /**
     * @param btnLogin the btnLogin to set
     */
    public void setBtnLogin(HtmlCommandButton btnLogin) {
        this.btnLogin = btnLogin;
    }
}
